package com.dmall.algorithm.chapter01;

import java.util.Arrays;

public class Leetcode1V2 {
    public int[] twoSum(int[] nums, int target){
        int volume = 2<<10; //2048
        int bitNum = volume-1; //11111111111
        int[] res = new int[volume];
        for(int i=0;i<nums.length;i++){
            int c = (target-nums[i])&bitNum;
            if(res[c]!=0){
                return new int[]{res[c]-1,i};
            }
            res[nums[i]&bitNum] = i+1;
        }
        throw new IllegalArgumentException("No two sum solution");
    }

    public static void main(String[] args) {
        int[] nums = {3, 3};
        Leetcode1V2 leetcode1 = new Leetcode1V2();
        int[] res = leetcode1.twoSum(nums, 6);
        System.out.println(Arrays.toString(res));
    }
}
